<!-- @format -->

<template>
  <el-form class="formWrapper" ref="form" v-bind="$attrs" v-on="$listeners" :visible.sync="visibleSon">
    <slot></slot>
    <el-form-item class="formBtnClass" style="display:block;/*width:80%*/" v-if="buttons.length">
      <nu-button v-if="buttons.includes('submit')" type="success" @click="submitForm('form')">确定</nu-button>
      <nu-button v-if="buttons.includes('search')" type="primary" @click="searchForm('form')">查询</nu-button>
      <nu-button v-if="buttons.includes('cancel')" type="primary" @click="cancelForm('form')">取消</nu-button>
      <nu-button v-if="buttons.includes('reset')" @click="resetForm('form')">重置</nu-button>
    </el-form-item>
  </el-form>
</template>

<script>
// import '../../src/assets/admin.css'
export default {
  name: 'verify-form',
  created() {
    this.visibleSon = this.visible;
    // console.log(this.$slots);
    // console.log(this.$attrs);
  },
  mounted() {},
  watch: {
    visibleSon: {
      handler(val) {
        this.$emit('update:visible', val);
      },
    },
    visible: {
      handler(val) {
        this.visibleSon = val;
      },
    },
  },
  data() {
    return {
      errMsg: '', //提示信息
      visibleSon: false,
    };
  },
  props: {
    // 展示按钮数组
    buttons: {
      type: Array,
      default: [],
    },
  },
  methods: {
    // 提交方法
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$emit('submitForm', true);
        } else {
          this.$emit('submitForm', false);
          return false;
        }
      });
    },
    // 查询方法
    searchForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$emit('searchForm', true);
        } else {
          this.$emit('searchForm', false);
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 重置表单方法
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 取消
    cancelForm(formName) {
      this.$emit('cancelForm');
      console.log('2222222222');
    },
  },
};
</script>
<style scoped>
.el-button {
  width: 120px;
  border-radius: 0px;
}
.el-button--success {
  background: #019290 !important;
}
.el-select-dropdown__item.selected {
  color: var(--select-selected) !important;
}
.el-select-dropdown__item:hover {
  background-color: var(--select-hover) !important;
}
.el-select .el-input.is-focus .el-input__inner {
  /* border-color: var(--select-selected) !important; */
}
::v-deep .el-input__inner {
  /* box-shadow:var(--input-box-shadow); */
  /* color:var(--input-color); */
  /* font-size:var(--form-input-fontsize) ; */
}
::v-deep .el-form-item {
  display: inline-block;
  margin: 10px;

  /* width: 276px; */
}
/* .input-div {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 240px;
  max-width: 400px;
} */
/* .label {
  display: inline-block;
  padding: 0px 10px;
  vertical-align: middle;
} */
/* .errMsg {
  position: absolute;
  color: red;
  font-size: 8px;
} */
.formBtnClass{
  text-align: center;
}
.formBtnClass ::v-deep .el-form-item__content{
  margin-left: 0 !important;
}

</style>
